Skip to content

Conversation

@DimitriPapadopoulos
Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented Nov 22, 2025

Companion to #124.

Mostly applied ruff pyupgrade (UP) rules, and some pycodestyle (E) and refurb (FURB) rules.

Edit: I have left out some pyupgrade (UP) rules:

  • UP030, UP031, UP032 are about moving string interpolation to f-strings. Change are pervasive, they are better left in a PR of their own.
  • UP036 implies lots of manual changes and requires extra care. Again, best left in a PR of its own.

@cclauss
Copy link
Contributor

cclauss commented Dec 1, 2025

Please consider the three ruff rule families in three separate pull requests so these changes are easier to review and merge.

@mattip
Copy link
Contributor

mattip commented Dec 1, 2025

Actually, I don't mind looking at this as one big PR. But #124 should go in first.

@mattip
Copy link
Contributor

mattip commented Dec 8, 2025

#124 is in. Want to take off the "Draft" status?

src/cffi/api.py Outdated
try:
callable
except NameError:
# Python 3.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Python 3.1

if isinstance(s, unicode):
s = s.encode('ascii')
super(NativeIO, self).write(s)
NativeIO = io.StringIO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could probably refactor out NativeIO

Comment on lines 58 to 60
prefix = 'PyInit_'
modname = self.verifier.get_module_name()
prnt("void %s%s(void) { }\n" % (prefix, modname))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about

Suggested change
prefix = 'PyInit_'
modname = self.verifier.get_module_name()
prnt("void %s%s(void) { }\n" % (prefix, modname))
modname = self.verifier.get_module_name()
prnt(f"void PyInit_{modname}(void) {{ }}\n")

Copy link
Contributor

@mattip mattip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot here, and probably a lot more to do. It is fine to do this in a couple of PRs though, we don't have to get it all in one PR.

@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented Dec 8, 2025

Yes, I'm mostly applying pyupgrade and refurb ruff rules, to handle everything that can be fixed or at least detected automatically. I was thinking of starting a manual pass once this PR is in. But sure, I can apply the above suggestions.

Still haven't applied UP030, UP031, UP032. I suggest a dedicated PR for these rules.

@DimitriPapadopoulos DimitriPapadopoulos marked this pull request as ready for review December 8, 2025 21:37
@DimitriPapadopoulos DimitriPapadopoulos force-pushed the python3 branch 7 times, most recently from 2bc183e to d396812 Compare December 8, 2025 22:49
@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented Dec 8, 2025

Looks like removing long has more side-effects than I thought.

Perhaps I need to move ec58eec / UP036 to a PR of its own.

UP004 Class inherits from `object`
UP008 Use `super()` instead of `super(__class__, self)`
UP009 UTF-8 encoding declaration is unnecessary
UP010 Unnecessary `__future__` import for target Python version

Manually removed comments about Unicode literals.
In Python 3, `io.open` is an alias for `open`.

This is a manual change, not detected by ruff.
UP024 Replace aliased errors with `OSError`
DimitriPapadopoulos and others added 8 commits December 10, 2025 09:52
UP025 Remove unicode literals from strings
UP028 Replace `yield` over `for` loop with `yield from`
UP035 Import from `collections.abc` instead: `Callable`

Co-authored-by: Matti Picus <[email protected]>
FURB129 Instead of calling `readlines()`, iterate over file object directly
FURB188 Prefer `str.removeprefix()` over conditionally replacing with slice.
E703 Statement ends with an unnecessary semicolon
E711 Comparison to `None` should be `cond is not None`
E713 Test for membership should be `not in`
@DimitriPapadopoulos
Copy link
Contributor Author

Rebased and deferred UP036 to a PR of its own.

@DimitriPapadopoulos DimitriPapadopoulos changed the title Remove pre-Python 3.8 code Start removing pre-Python 3.8 code Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants